package com.cloud.Batch;

import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.UUID;
import java.util.concurrent.CyclicBarrier;

/**
 * @author: create by God of SJF
 * @version: v1.0
 * @description: com.cloud
 * @date:2021/6/3
 */
public class Batch implements  Runnable {


    CyclicBarrier cyclicBarrier;


    Connection connection;

    @SneakyThrows
    @Override
    public void run() {
        try {
            String sql = "insert into dealer(code,name)values(?,?)";
            PreparedStatement prepareStatement = connection.prepareStatement(sql);
            prepareStatement.setString(1, String.valueOf(UUID.randomUUID()).replaceAll("-", ""));
            prepareStatement.setString(2, "b");
            prepareStatement.execute();
        }catch (Exception e){
            cyclicBarrier.reset();
        }
        cyclicBarrier.await();
    }

    Integer id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public CyclicBarrier getCyclicBarrier() {
        return cyclicBarrier;
    }

    public void setCyclicBarrier(CyclicBarrier cyclicBarrier) {
        this.cyclicBarrier = cyclicBarrier;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }
}
